/********************************************************************************
Title: Data Preparation for Kenya iPUSH Sample
		Define time points
		Define variables to use in each index
		Define survey round to use as reference round
********************************************************************************/

loc ref round == 1

*----------------------------------

use  "${raw}/kenya_ipush/kenya_ipush_desc.dta", clear
keep if !mi(pid)
keep if !mi(round)
sort pid date
collapse (firstnm) age ses female, by(pid)
tempfile desc
save `desc'

use  "${raw}/kenya_ipush/kenya_ipush.dta", clear
cap drop age
cap drop female
cap drop ses


*-------------------------------------------------------------------------------
*			0. Formating and Renaming Variables
*-------------------------------------------------------------------------------

*			0.1		PID and HHID
*-------------------------------------------------------------------------------

keep if !mi(pid)
keep if !mi(round)
*isid pid round
tostring hhid, replace


merge m:1 pid using `desc', nogen


*			0.2		Month
*-------------------------------------------------------------------------------
replace date = . if date < mdy(1,1,2018)
gen month = month(date) - 10 + 12*year(date) - 12*2019
tab month

*-------------------------------------------------------------------------------
*			1. Generating Variable Lists
*-------------------------------------------------------------------------------
macro drop depression vars 
gl reverse depression effort concentration difficulties cesd_score  

foreach var of varlist $reverse {
	replace `var' = -1*`var'
}

gl vars depression sleep effort concentration difficulties  

*-------------------------------------------------------------------------------
*			2. Generating Indices
*-------------------------------------------------------------------------------

foreach var in $vars cesd_score {
	sum `var' if `ref'
	replace `var' = (`var' - `r(mean)')/`r(sd)'
	gen swt_`var' = `var'
}

factor depression sleep concentration difficulties  if  `ref', ipf factor(1)
predict ___depression_fw


gen month_seas = month(date) + 2
recode month_seas (11 12 = 0) (13 = 1) (14 = 2)
tab month_seas

*-------------------------------------------------------------------------------
*          Unweighted indices
*-------------------------------------------------------------------------------
gen ___depression_nw = cesd_score


*-------------------------------------------------------------------------------
*          Inverse-covariance-weighted indices
*-------------------------------------------------------------------------------
icw_index(depression sleep concentration difficulties), gen(___depression_icw)


* Checking Cronbach's alpha
*Validated tool CESD-10
alpha score_mh_q01-score_mh_q10 // Scale reliability coefficient= 0.773
*Weighted depression score
alpha depression sleep concentration difficulties  // Scale reliability coefficient= 0.717

reg ___depression_nw ses







